using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Input;

namespace SharpMap.Presentation.Wpf
{
    /// <summary>
    /// Provides the means to handle mouse wheel actions throught the WPF command system
    /// <see cref="http://cebla5.spaces.live.com/blog/cns!1B8262ED00250003!133.entry"/>
    /// </summary>
    public class MouseWheelGesture : MouseGesture
    {

        private MouseWheelAction mouseWheelAction;

        public MouseWheelAction MouseWheelAction
        {
            get { return mouseWheelAction; }
            set { mouseWheelAction = value; }
        }

        public MouseWheelGesture()
            : base(MouseAction.WheelClick)
        {
            mouseWheelAction = MouseWheelAction.AllMovement;
        }

        public MouseWheelGesture(MouseWheelAction wheelGesture)
            : base(MouseAction.WheelClick)
        {
            mouseWheelAction = wheelGesture;
        }

        public override Boolean Matches(object targetElement, InputEventArgs inputEventArgs)
        {
            if (base.Matches(targetElement, inputEventArgs))
            {
                MouseWheelEventArgs wheelArgs = inputEventArgs as MouseWheelEventArgs;
                if (wheelArgs != null)
                {
                    if (MouseWheelAction == MouseWheelAction.AllMovement
                            || (MouseWheelAction == MouseWheelAction.WheelDown && wheelArgs.Delta < 0)
                            || MouseWheelAction == MouseWheelAction.WheelUp && wheelArgs.Delta > 0)
                    {
                        return true;
                    }
                }
            }

            return false;
        }
    }

    public enum MouseWheelAction
    {
        AllMovement,
        WheelUp,
        WheelDown
    }
}
